<?php
class File {
	/**
	 * 删除文件
	 * @param unknown $path
	 */
	public function deleteFile($path){
		if (file_exists($path)){
			unlink($path);
		}
	}
	/**
	 * 创建文件夹
	 */
	public function createFolder($path)
	{
		$wjs=explode(DIRECTORY_SEPARATOR,$path);
		$i=0;
		$wjjma="";
		while ($i<count($wjs))		{
			$wma=$wjs[$i];
			if (($i+1)<>count($wjs))
			{
				$wma=$wjs[$i].DIRECTORY_SEPARATOR;
			}
			$wjjma=$wjjma.$wma;
				if (!file_exists($wjjma)){
					mkdir ($wjjma,0777);
				}
			$i++;
		}
	}
	/**
	 * 生成文件
	 */
	public function generationFile ($path,$data)	{
		if(file_exists($path)){
			$fpa=fopen($path,"w");
			fwrite($fpa,$data);
			fclose($fpa);
		}
	}
	/**
	 * 生成文件夹和文件
	 * @param unknown $path
	 * @param unknown $fileName
	 * @param unknown $data
	 */
	public function fileorFolder($path,$fileName,$data)
	{
		
		if (!file_exists($path))		{
		
			$this->createFolder($path);
		}
		
		$filePath=$path.DIRECTORY_SEPARATOR.$fileName;
		$this->generationFile($filePath, $data);
	}
	/**
	 * 删除文件
	 * @param unknown $dir 文件路径
	 * @return boolean
	 */
	public function deldir($dir)
	{
		if (!file_exists($dir))	{
			return true;
		}
		
		$dh = opendir($dir);
		while ($file = readdir($dh))
		{
			if ($file != "." && $file != "..")
			{
				$fullpath = $dir . "/" . $file;
				if (!is_dir($fullpath))
				{
					unlink($fullpath);
				} else
				{
					$this->deldir($fullpath);
				}
			}
		}
		closedir($dh);
		if (rmdir($dir))
		{
			return true;
		} else
		{
			return false;
		}
	}
}

?>